import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:myfirstflutter/pages/home/home_property_page.dart';
import 'package:myfirstflutter/utils/zone_item_style.dart';
import 'package:myfirstflutter/widgets/column_button.dart';

class HomePageWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new HomePageWidgetState();
  }
}

class HomePageWidgetState extends State<HomePageWidget>
    with AutomaticKeepAliveClientMixin {
  void zoneItemClicked(ZoneItemStyle style) {
    print(style);
     Navigator.push(context,
                  new MaterialPageRoute(builder: (context) => new HomePropertyPageWidget()));
  }

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    var imageList = new List();
    imageList
      ..add(
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574006406219&di=713ff100a166added19d68a4c2bf520a&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Fb1cce6f996734bdbb9b3fb9ef7705deabc980e35493b-ysf8BZ_fw658')
      ..add(
          'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3746588040,3647927995&fm=26&gp=0.jpg')
      ..add(
          'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574006406218&di=9b3a4d1e23ac6c6abe4745568713fbe7&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F9b671d17b52639d35e7c76c23f79fbabebe769d43140-xjB5Tw_fw658');
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('首页'),
        brightness: Brightness.light,
        backgroundColor: Colors.white,
      ),
      body: new Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: 15),
            height: 170.0,
            child: new Swiper(
              itemBuilder: (BuildContext context, int index) {
                return new ClipRRect(
                    borderRadius: BorderRadius.circular(10.0),
                    child: new Image.network(
                      imageList[index],
                      fit: BoxFit.fill,
                    ));
              },
              itemCount: 3,
              viewportFraction: 0.8,
              scale: 0.9,
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 7, top: 20, right: 7),
            padding: EdgeInsets.all(15),
            decoration: new BoxDecoration(
              color: Colors.white,
              borderRadius: new BorderRadius.all(new Radius.circular(15.0)),
            ),
            height: 170,
            child: new Wrap(spacing: 20, runSpacing: 20, children: <Widget>[
              ImageButton(
                normalImageString: 'images/home_property.png',
                title: '园区资产管理',
                onPressed: () {
                  zoneItemClicked(ZoneItemStyle.homeProperty);
                },
              ),
              ImageButton(
                normalImageString: 'images/home_synergy.png',
                title: '园企协同',
                onPressed: () {
                  zoneItemClicked(ZoneItemStyle.homeSynergy);
                },
              ),
              ImageButton(
                normalImageString: 'images/home_finance.png',
                title: '财务管理',
                onPressed: () {
                  zoneItemClicked(ZoneItemStyle.homeFinance);
                },
              ),
              ImageButton(
                normalImageString: 'images/home_brain.png',
                title: '园区大脑',
                onPressed: () {
                  zoneItemClicked(ZoneItemStyle.homeBrain);
                },
              ),
              ImageButton(
                normalImageString: 'images/home_apartment.png',
                title: '人才公寓',
                onPressed: () {
                  zoneItemClicked(ZoneItemStyle.homeApartment);
                },
              ),
              ImageButton(
                normalImageString: 'images/home_grow_up.png',
                title: '企业成长分析',
                onPressed: () {
                  zoneItemClicked(ZoneItemStyle.homeGrowUp);
                },
              ),
            ]),
          )
        ],
      ),
    );
  }
}
